import request from "@/service/request";
import {PromiseResponse} from "@/service/api/type.ts";
import {RegionSelectionVo, SysRegionVo} from "@/service/api/system/region/types.ts";

/**
 * 获取所有区域及选择区域
 */
const getDefaultRegionTree = (): PromiseResponse<RegionSelectionVo> => {
  return request({
    url: "/region/allTreeselect",
    method: "get",
  });
};

/**
 * 新增地区
 * @param query
 */
const addRegion = (query: any): PromiseResponse<any> => {
  return request({
    url: "/region",
    method: "post",
    data: query,
  });
};

/**
 * 获取地区详情
 * @param id
 */
const getRegionDetail = (id: string): PromiseResponse<SysRegionVo> => {
  return request({
    url: `/region/${id}`,
    method: "get",
  });
};

/**
 * 编辑地区
 * @param query
 */
const updateRegion = (query: any): PromiseResponse<any> => {
  return request({
    url: "/region/edit",
    method: "put",
    data: query,
  });
};

/**
 * 删除地区
 * @param ids
 */
const deleteRegion = (ids: string | string[]): PromiseResponse<any> => {
  return request({
    url: `/region/${ids}`,
    method: "delete",
  });
};

/**
 * 保存地区的选择
 * @param ids
 */
const saveRegionSelection = (ids: string[]): PromiseResponse<any> => {
  return request({
    url: "/region/showRegion",
    method: "post",
    data: ids
  });
};

export {
  getDefaultRegionTree,
  addRegion,
  getRegionDetail,
  updateRegion,
  deleteRegion,
  saveRegionSelection
};
